package untils

import "net"

func GetAddr() (int, error) {
	//定义协议和地址
	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
	if err != nil {
		return 1, err
	}
	//监听
	watch, err := net.ListenTCP("tcp", addr)
	//关闭监听
	defer watch.Close()
	return watch.Addr().(*net.TCPAddr).Port, err
}
